var tablename = "chat";
var $ = require("../../include/$");
module.exports = {
	get: function(req, res) {
		var data = req.query;
		req.models[tablename].get(data.chatid, function(err, result) {
			// console.log(eval(result.chat));
			res.send(result);
			res.end();
		});
	},
	put: function(req, res) {
		tablename = "chat";
		var data = req.body;
		console.log("data", data);
		// console.log("为表“", tablename, "”进行修改：", req.body, req.query);
		req.models[tablename].get(data.chatid, function(err, result) {
			// eval(result.chat);
			// console.log(result)
			var _array = eval(result.chat);
			_array.push(data.msg);
			result.chat = JSON.stringify(_array);
			result.save(function(err) {
				if (err) {
					res.send(500, err);
				};
			});
			res.end();
		});
	}
}
module.exports.cache = false;